#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    double dp[110][30][30] = { 0.0 };
    int dx[8] = { -2, -2, -1, -1, 1, 1, 2, 2 };
    int dy[8] = { -1, 1, -2, 2, -2, 2, -1, 1 };
    double res = 0;
    double knightProbability(int n, int k, int row, int column) {
        for (int i = 0; i <= k; i++)
        {
            for (int x = 0; x < n; x++)
            {
                for (int y = 0; y < n; y++)
                {
                    if (i == 0) dp[i][x][y] = 1.0;
                    else
                    {
                        for (int j = 0; j < 8; j++)
                        {
                            int a = x + dx[j];
                            int b = y + dy[j];
                            if (a >= 0 && a < n && b >= 0 && b < n)
                            {
                                dp[i][x][y] += 0.125 * dp[i - 1][a][b];
                            }
                        }
                    }
                }
            }
        }
        return dp[k][row][column];
    }
};